<% include("../../common/header.html",{title:"创建问卷",active:4}){} %>
<!-- main start -->
<div class="surBox">
<!-- meanu start -->
<div style="border-bottom:1px dashed #ccc;">
	<h1 style="font-size:18px;font-weight: normal;text-align: left;color:#a4a4a4;padding-left:20px; margin:0; display:inline-block;margin-right:30px;">
	请填写以下内容创建问卷...
	</h1>
</div>
<!-- meanu end -->

<!-- form start -->
<div class="formBox" style="margin-top:20px;">
<form class="form-horizontal" action="addSurvey" method="post" id="add_form">
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">问卷名称</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name="title" id="title" placeholder="请填写问卷标题">
    </div>
  </div>
  
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">问卷结束时间</label>
    <div class="col-sm-5">
      <input type="text" class="form-control" name="expireTime" id="datetimepicker" style="width:310px" readonly placeholder="点击选择日期">
    </div>
  </div>
  
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">是否公开</label>
    <div class="col-sm-10">
      <label><input type="radio"  name="isOpen" value="true" id="is_open_true" checked="checked">公开</label>
      <label><input type="radio" name="isOpen" value="false" id="is_open_false">私密</label>
      <label style="margin-left:20px;" id="not_open"></label>
    </div>
  </div>
  
	<div class="form-group">
	<label for="inputPassword3" class="col-sm-2 control-label">问卷描述</label>
	<div class="col-sm-10">
	  <script name="sdesc" id="editor" type="text/plain" style="width:100%;height:200px;">暂无问卷介绍...</script>
	</div>
	</div>
  
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="button" class="btn btn-success" onclick="check();">　我 填 好 了　</button>
      <button type="reset" style="margin-left:100px;" class="btn btn-success">　我 要 重 写　</button>
    </div>
  </div>
</form>
</div>
<!-- form end -->

</div>
<!-- main end -->

<!-- 加载ueditor所需静态资源 -->
<script type="text/javascript" charset="utf-8" src="${ctxPath}/static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="${ctxPath}/static/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="${ctxPath}/static/ueditor/lang/zh-cn/zh-cn.js"></script>
<!-- 加载日期时间控件所需静态资源 -->
<link rel="stylesheet" type="text/css" href="${ctxPath}/static/datetimepicker/jquery.datetimepicker.css" />
<script type="text/javascript" src="${ctxPath}/static/datetimepicker/jquery.datetimepicker.js"></script>
    
<script type="text/javascript">
var flg = 0;
$(document).ready(function() {  
    $("#is_open_false").click(function (e){  
        if(flg == 0){
        $("#not_open").append('<input type="password" class="form-control" name="password" id="password" placeholder="请输入访问密码">');
        flg = 1;
        }
    });
    $("#is_open_true").click(function (e){  
        if(flg == 1){
        $("#password").remove();
        flg = 0;
        }
    });
    
});

// 实例化UE
var ue = UE.getEditor('editor');
// 实例化日期时间控件
$('#datetimepicker').datetimepicker({lang:'ch',format:'Y-m-d H:i',});

function check(){
	var title = $("#title").val().length;
	var datetime = $("#datetimepicker").val();
	var datetimeReg = /^([0-9]){4}-([0-9]){2}-([0-9]){2} ([0-9]){2}:([0-9]){2}$/;
	var password = $("#password").val();
	var passwordReg = /^[a-zA-Z\w]{5,17}$/;
	var success = true;
	
	if(title == 0 || title > 200){
	    layer.tips('标题必须大于0小于200!', "#title",{
	        tips: [1, '#78BA32'] ,tipsMore: true
	    }); 
	    success = false;
	}
	if(!datetimeReg.test(datetime)){
	    layer.tips('日期时间格式错误!', "#datetimepicker",{
	        tips: [2, '#78BA32'] ,tipsMore: true
	    }); 
	    success = false;
	}
	if(flg == 1 && !passwordReg.test(password)){
	    layer.tips('密码格式错误!', "#password",{
	        tips: [2, '#78BA32'] ,tipsMore: true
	    }); 
	    success = false;
	}
	if(success){
	     $.post(
	    		"addSurvey",
	    		$("#add_form").serialize(),
	    		function(data) {
	    			if(!data.status) {
	    			    layer.msg(data.msg);
	    			    return;
	    			}else{
	    			    layer.msg(data.msg, {icon: 16}, function(){
						      //关闭后的操作
	    			        location.href="${ctxPath}/manager/questionView/" + data.others ;
					      });
	    			}
	    		},
		    	"json"
	    ); 
	}
}

</script>

<% include("../../common/footer.html"){} %>